<template>
  <div>
    <van-tabbar v-model="active">
      <van-tabbar-item name="home" icon="graphic">店长管理</van-tabbar-item>
      <van-tabbar-item name="search" icon="manager">社长管理</van-tabbar-item>
      <van-tabbar-item name="friends" icon="gold-coin">区长管理</van-tabbar-item>
    </van-tabbar>
    <!-- 店长 -->
    <div class="content" v-if="active == 'home'">
      <div>
        <div class="s-card" v-if="agent.roledec">
          <div class="s-card-text">{{ agent.roledec + "：" + agent.phone }}</div>
        </div>
        <div class="btn4" @click="reset">退出登录</div>
      </div>


      <div class="card1" v-for="(item, index) in list" :key="index">

        <div class="card1-title">商户信息</div>

        <div style="display: flex;justify-content: space-around;">
          <div class="card1-text">商户名称：{{ item.name }}</div>
          <div class="card1-text">手机号：{{ item.phone }}</div>
        </div>

        <div style="display: flex;justify-content: space-around;">

          <div class="card1-text">类型：{{ item.roledec }}</div>
          <div class="card1-text">状态：{{ item.statedec }}
            <div class="btn-new" @click="noAllow(item)" v-if="item.state == 1">禁用</div>
            <div class="btn-news" @click="Allow(item)" v-else-if="item.state == 2">启用</div>
          </div>
        </div>
        <div style="display: flex;justify-content: space-around;">
          <div class="card1-text">用户数： <span style="color: red;">{{ item.userNumber + '人' }}</span> </div>
          <div class="card1-text">会员人数：<span style="color: red;">{{ item.superNumber + '人' }}</span> </div>
        </div>
        <div style="display: flex;justify-content: space-around;">
          <div class="card1-text">店铺名称：{{ item.storename }}</div>
          <div class="card1-text">
            代金券金额：<span v-if="item.voucher" style="color: red">{{ item.voucher }}元</span>
          </div>
        </div>
        <div style="display: flex;justify-content: space-around;">
          <div class="card1-text">会员类型： <span style="color: red">{{ item.memberType ? item.memberType == 1 ? '盟主版永久会员'  : item.memberType == 2 ? '企业版年度会员' : item.memberType == 3 ? '临时会员' : '暂无会员' : '暂无会员' }}</span></div>
          <div class="card1-text">
            <div class="btnMember" @click="btnMember(item)">设置会员类型</div>
          </div>

        </div>
       
        <div style="display: flex;justify-content: space-around;">
          <div style="display: flex;justify-content: space-around;">
          <div class="card1-text">注册时间：{{ item.time }}</div>
        </div>
          <div class="card1-text">
            <div class="btnMember" @click="changeShop(item)" style="width: 1.8rem;">更换店长</div>
          </div>

        </div>
        <div style="display: flex;justify-content: space-around;">
          <div style="display: flex;justify-content: space-around;">
          <div class="card1-text">商城开关： <div class="btn-new" @click="setOpen(item)" v-if="item.storeOpen == 1">关闭</div>
            <div class="btn-news" @click="setOpen(item)" v-else-if="item.storeOpen == 0">打开</div></div>
        </div>
          <div class="card1-text">
           
          </div>

        </div>
        <div style="display: flex;justify-content: space-around;" v-if="item.dec">

          <div class="card1-text" style="color:red">备注：{{ item.dec }}</div>
        </div>
        <div class="btn">
          <div class="btn1" @click="btn3(item)">修改余额</div>
          <div class="btn1" @click="btn4(item)">重置密码</div>
        </div>
        <div class="btn" style="margin-top:.2rem;">
          <div class="btn2" @click="btn1(item)">充值记录</div>
          <div class="btn2" @click="btn2(item)">发放记录</div>
        </div>
      </div>
      <div class="addStore" @click="addMember(1)">
        新增店长
      </div>
      <div class="addStore1" @click="addMembers(1)">
        店长邀请函
      </div>
    </div>
    <!-- 社长 -->
    <div class="content" v-if="active == 'search'">
      <div class="s-card" v-if="agent.roledec">
        <div class="s-card-text">{{ agent.roledec + "：" + agent.phone }}</div>
      </div>
      <div class="btn4" @click="reset">退出登录</div>
      <div class="btn4" style="margin-right: .1rem;" @click="btn6">提现处理</div>
      <div class="card1" v-for="(item, index) in presidentList" :key="index">

        <div class="card1-title">商户信息</div>

        <div style="display: flex;justify-content: space-around;">
          <div class="card1-text">商户名称：{{ item.name }}</div>
          <div class="card1-text">手机号：{{ item.phone }}</div>
        </div>
        <div style="display: flex;justify-content: space-around;">
          <div class="card1-text">用户数： <span style="color: red;">{{ item.userNumber + '人' }}</span> </div>
          <div class="card1-text">会员人数：<span style="color: red;">{{ item.superNumber + '人' }}</span> </div>
        </div>
        <div style="display: flex;justify-content: space-around;">
          <div class="card1-text">注册时间：{{ item.time }}</div>
          <div class="btn4" @click="btn4(item)" style="background-color: #ffbe4c">重置密码</div>
        </div>
        <div style="display: flex;justify-content: space-around;" v-if="item.dec">
          <div class="card1-text" style="color:red">备注：{{ item.dec }}</div>
        </div>
        <!--  <div class="btn">
          
          <div class="btn2" @click="btn5(item)">提现申请列表</div>
          <div class="btn2" @click="btn6(item)">提现申请记录</div>
        </div> -->
      </div>
      <div class="addStore" @click="addMember(2)">
        新增社长
      </div>
      <div class="addStore1" @click="addMembers(2)">
        社长邀请函
      </div>
    </div>
    <!-- 社长 -->
    <div class="content" v-if="active == 'friends'">
      <div class="s-card" v-if="agent.roledec">
        <div class="s-card-text">{{ agent.roledec + "：" + agent.phone }}</div>
      </div>
      <div class="btn4" @click="reset">退出登录</div>
      <div class="title">
        敬请期待！
      </div>
    </div>
    <!-- 设置支付会员类型弹窗 -->
    <van-dialog v-model="isSureShow" title="" :show-cancel-button="false" :showConfirmButton="false" width="70%">
      <div class="dialog-title">设置会员类型</div>
      <div style="padding-bottom:.3rem;">
        <van-radio-group v-model="radio" icon-size="18px">
          <van-radio name="1" style="margin-top: .2rem;" checked-color="#ee0a24">盟主版永久会员</van-radio>
          <van-radio name="2" style="margin-top: .2rem;" checked-color="#ee0a24">企业版年度会员</van-radio>
          <van-radio name="3" style="margin-top: .2rem;" checked-color="#ee0a24">临时会员</van-radio>
        </van-radio-group>
      </div>
      <div style="display: flex;">
        <div class="dloBtnS" style="flex:1" @click="isSureShow = false">取消</div>
        <div class="dloBtn" style="flex:1;margin-left: .1rem;" @click="sumbitFn">确定</div>
      </div>
      
    </van-dialog>
    <van-popup class="popup" v-model="changeShow" :close-on-click-overlay="false">
      <div class="editWord">
        <div class="dialog-title">更换店长</div>
        <form action="" class="form">

          <input style="margin-top: 0.6rem" class="input" type="number" v-model="changePhone" id="number"
            placeholder="请输入手机号" />
        </form>
        <div style="display: flex;margin-top: .5rem;" >
        <div class="dloBtnS" style="width: 40%;" @click="changeShow = false">取消</div>
        <div class="dloBtn" style="width: 40%;margin-left: .1rem;" @click="sumbitChangePhoneFn">确定</div>
      </div>
      </div>
    </van-popup>
  </div>
</template>

<script>
import { indexdata, resetPwd, allow, ban, getMemberType, setVip ,replaceManager,setStore} from "@/api/fulfil.js";
export default {
  name: 'supertube',
  data() {
    return {
      agent: {},
      store: {},
      ticket: {},
      list: [],
      active: 'home',
      isSureShow: false,
      presidentList: [],//社长列表
      radio: '',
      memberList: [],//会员类型列表
      memberId: '',//会员类型
      changePhone:'',//更换手机号
      changeShow:false, //更换店长弹窗
      changePhoneId:'',//更换店长id
    };
  },
  created() { },
  mounted() {
  },
  activated() {
    let uid = localStorage.getItem("agentids");
    this.getMember();
    if (!uid) {
      this.$Toast("请先登录！");
      this.$router.push({
        path: "/login",
      });
    } else {
      this.getIndex();
    }
  },
  methods: {
    //确定
    sumbitFn() {
      if (!this.radio) {
        this.$Toast("请选择要设置的会员类型");
        return false;
      }
      setVip({
        adminid: localStorage.getItem("agentids"),
        agentid: this.memberId,
        memberType: this.radio,
      })
        .then((res) => {
          if (res.data.code == 0) {
            this.$Toast("设置会员类型成功");
            this.isSureShow = false;
            this.getIndex();
          }else{
            this.$Toast(res.data.msg);
          }
          console.log(res, 'res');

        })
        .catch((error) => {
          this.isSureShow = false;
          console.log(error);
        });

    },
    //新增商户
    addMember(type) {
      if (type == 1) {
        localStorage.setItem('addstoreType', 1)
      } else if (type == 2) {
        localStorage.setItem('addstoreType', 2)
      }
      this.$router.push({
        path: "/addstore",
      });
    },
     //邀请函
     addMembers(type) {
      if (type == 1) {
        this.$router.push({
        path: "/Tournament1",
      });
      } else if (type == 2) {
        this.$router.push({
        path: "/Tournament2",
      });
      }
      
    },
    //退出登录
    reset() {
      localStorage.removeItem("adminid");
      localStorage.removeItem("agentid");
      localStorage.removeItem("agentids");
      localStorage.removeItem("phone");
      localStorage.removeItem("password");
      localStorage.removeItem("role");
      localStorage.removeItem("openid");
      localStorage.removeItem("Notice");
      this.$router.push({
        path: "/login",
      });
    },

    btn3(item) {
      localStorage.setItem("adminid", item.id);
      this.$router.push({
        path: "/supertubedit",
        query: { item: item },
      });
    },
    //充值密码
    btn4(item) {
      this.resetPwd(item);
    },
    //设置会员类型
    btnMember(item) {
      this.isSureShow = true;
      this.memberId = item.id;
    },
    //更换店长
    changeShop(item){
      this.changePhoneId = item.id;
      this.changeShow = true;
    },
    sumbitChangePhoneFn(){
      replaceManager({
        adminid: localStorage.getItem("agentids"),
        agentid: this.changePhoneId,
        newphone: this.changePhone,
      })
        .then((res) => {
          if (res.data.code == 0) {
            this.$Toast("更换店长成功");
            this.changeShow = false;
            this.changePhone = '';
            this.getIndex();
          }else{
            this.$Toast(res.data.msg);
          }
          console.log(res, 'res');

        })
        .catch((error) => {
          this.changeShow = false;
          console.log(error);
        });
    },
    //提现处理
    btn5() {
      this.$router.push({
        path: "/withRquest"
      });
    },
    //提现申请列表
    btn6() {
      localStorage.setItem('cashType', 2);
      this.$router.push({
        path: "/cash"
      });
    },
    //获取会员类型
    getMember() {
      getMemberType({
        agentid: localStorage.getItem("agentids")
      })
        .then((res) => {
          console.log(res, 'res');
          this.memberList = res.data.data;
          console.log(this.memberList, 'this.memberList');
        })
        .catch((error) => {
          console.log(error);
        });
    },
    //是否开启店铺
    setOpen(item) {
      setStore({
        adminid: localStorage.getItem("agentids"),
        agentid: item.id,
        open:item.storeOpen == 0 ? '1' : '0'
      })
        .then((res) => {
          if (res.data.code == 0) {
            this.$Toast("该店长店铺开关操作成功");
            this.getIndex();
          } else {
            this.$Toast(res.data.msg);
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    //禁用
    noAllow(item) {
      ban({
        adminid: localStorage.getItem("agentids"),
        agentid: item.id
      })
        .then((res) => {
          if (res.data.code == 0) {
            this.$Toast("该店长账户禁用成功！");
            this.getIndex();
          } else {
            this.$Toast(res.data.msg);
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    //启用
    Allow(item) {
      allow({
        adminid: localStorage.getItem("agentids"),
        agentid: item.id
      })
        .then((res) => {
          if (res.data.code == 0) {
            this.$Toast("该店长账户启用成功！");
            this.getIndex();
          } else {
            this.$Toast(res.data.msg);
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    //重置密码
    resetPwd(item) {
      resetPwd({
        adminid: localStorage.getItem("agentids"),
        agentid: item.id
      })
        .then((res) => {
          if (res.data.code == 0) {
            this.$Toast("该店长密码重置成功！");
          } else {
            this.$Toast(res.data.msg);
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    getIndex() {
      indexdata({
        agentid: localStorage.getItem("agentids"),
        role: localStorage.getItem("role")
      })
        .then((res) => {
          let list = res.data.data.agents;
          this.list = [];
          list.forEach((item) => {
            if (item.role == 1) {
              this.list.push(item);
            } else if (item.role == 2) {
              this.presidentList.push(item);
            }
          })
          this.store = res.data.data.store;
          this.agent = res.data.data.agent;
          console.log(res);
        })
        .catch((error) => {
          console.log(error);
        });
    },
    btn1(item) {
      localStorage.setItem("adminid", item.id);
      this.$router.push({
        path: "/record1",
      });
    },
    btn2(item) {
      localStorage.setItem("adminid", item.id);
      this.$router.push({
        path: "/record2",
      });
    },
  },
};
</script>

<style scoped>
.content {
  position: relative;
  padding-bottom: 2rem;
  overflow: hidden;
  width: 100%;
  min-height: 100vh;
  background: #e1f7fc;
}

.card1 {
  overflow: hidden;
  margin: 0.3rem auto 0;
  padding: 0 0.5rem 0.25rem 0.5rem;
  width: 84%;
  background: #fff;
  border-radius: 0.375rem;
}

.van-dialog {
  padding: 0 .5rem;
  box-sizing: border-box;
}

.card1-title {
  margin-top: 0.2rem;
  font-size: 0.4125rem;
  font-weight: 600;
  color: #000;
}

.card1-text {
  flex: 1;
  display: inline-block;
  margin: 0.25rem 0 0 0.2rem;
  font-size: 0.3125rem;
  font-weight: 600;
  color: #000;
}

.card1-text1 {
  margin: 0.25rem 0 0 0.2rem;
  font-size: 0.3125rem;
  font-weight: 600;
  color: #000;
  text-align: center;
}

.btn {
  margin-top: 0.6rem;
  display: flex;
  /* 应用Flex布局 */
  justify-content: space-between;
  /* 控制盒子之间的对齐方式 */
}

.btn1 {
  width: 50%;
  padding: 0 .3rem;
  height: 1rem;
  color: #000;
  text-align: center;
  line-height: 1rem;
  border-radius: 0.5rem;
  background-color: #FFD584;
}

.btnMember {
  width: 2.3rem;
  padding: 0 .1rem;
  height: 0.75rem;
  color: #000;
  text-align: center;
  line-height: 0.75rem;
  border-radius: 0.375rem;
  background-color: #7efed3;
}
.popup {
  border-radius: .5rem;
  width: 80%;
  border: 0.0625rem solid rgb(255, 255, 255);
  box-shadow: rgba(133, 189, 215, 0.8784313725) 0px 0.375rem 0.375rem --0.25rem;
  background: linear-gradient(0deg, rgb(255, 255, 255) 0%, rgb(244, 247, 251) 100%);
}

.btn4 {
  margin: 20px 30px 20px 0;
  float: right;
  width: 2rem;
  height: 0.75rem;
  color: #000;
  text-align: center;
  line-height: 0.75rem;
  border-radius: 0.375rem;
  background-color: #ffaa7f;
}

.s-card-text {
  margin: .25rem 0 .25rem .475rem;
  height: 0.75rem;
  line-height: 0.75rem;
  float: left;
  color: #000;
  font-size: 0.45rem;
  font-weight: 600;
}

.btn2 {
  width: 50%;
  padding: 0 .3rem;
  height: 1rem;
  line-height: 1rem;
  text-align: center;
  color: #000;
  border-radius: 0.5rem;
  background-color: #ffbe4c;
}

.dloTtxt {
  margin-top: .2rem;
  font-size: .35rem;
}

.btn-new {
  display: inline-block;
  padding: .1rem .2rem;
  color: #fff;
  border-radius: 0.375rem;
  background-color: #f44;
}

.btn-news {
  display: inline-block;
  padding: .1rem .2rem;
  color: #fff;
  border-radius: 0.375rem;
  background-color: #07c160;
}

.dloBtn {
  display:inline-block;
  width: 40%;
  height: .8rem;
  background: #7efed3;
  color: #000;
  border-radius: .5rem;
  text-align: center;
  line-height: .8rem;
  margin: .3rem auto;
}
.dloBtnS {
  display:inline-block;
  width: 40%;
  height: .8rem;
  background: #ffbe4c;
  color: #000;
  border-radius: .5rem;
  text-align: center;
  line-height: .8rem;
  margin: .3rem auto;
}
.sao {
  margin: 2rem auto 0;
  width: 60%;
  text-align: center;
  height: 1rem;
  line-height: 1rem;
  font-size: 0.35rem;
  border-radius: 0.5rem;
  background-color: #ffbe4c;
  font-weight: 600;
}

.dialog-title {
  margin: .3rem;
  text-align: center;
  font-size: .4rem;
  color: #000;
}

.addStore {
  position: fixed;
  bottom: 1rem;
  left: 4%;
  width: 46%;
  height: 1rem;
  font-size: .4rem;
  text-align: center;
  color: #AD3516;
  background: linear-gradient(180deg, #FFE9C6, #FFD584);
  box-shadow: 0px 3px 8px 0px rgba(150, 51, 20, 0.42);
  line-height: 1rem;
  border-radius: .5rem;
}
.addStore1 {
  position: fixed;
  bottom: 1rem;
  right: 4%;
  width: 46%;
  height: 1rem;
  font-size: .4rem;
  text-align: center;
  color: #AD3516;
  background: linear-gradient(180deg, #FFE9C6, #FFD584);
  box-shadow: 0px 3px 8px 0px rgba(150, 51, 20, 0.42);
  line-height: 1rem;
  border-radius: .5rem;
}
.title {
  margin: 5rem auto;
  font-weight: 600;
  font-size: .35rem;
  color: #ffbe4c;
  text-align: center;
}


.input {
  margin-top: 1.2875rem;
  width: 90%;
  background: white;
  border: none;
  padding: 0.1875rem 0.25rem;
  border-radius: 0.25rem;
  box-shadow: #cff0ff 0px 0.125rem 0.125rem -0.0625rem;
  border-inline: 2px solid transparent;
}

.form .input::-moz-placeholder {
  color: rgb(170, 170, 170);
}

.form .input::placeholder {
  color: rgb(170, 170, 170);
}

.form .input:focus {
  outline: none;
  border-inline: 2px solid #12b1d1;
}

.form .forgot-password {
  display: block;
  margin-top: 0.125rem;
  margin-left: 0.125rem;
}

.form .forgot-password a {
  font-size: 0.375rem;
  color: #0099ff;
  text-decoration: none;
}

.form .login-button {
  display: block;
  width: 100%;
  font-weight: bold;
  background: linear-gradient(45deg,
      rgb(16, 137, 211) 0%,
      rgb(18, 177, 209) 100%);
  color: white;
  padding-block: 0.1875rem;
  margin: 2.5rem auto;
  border-radius: 0.25rem;
  box-shadow: rgba(133, 189, 215, 0.8784313725) 0px 0.25rem 0.125rem --0.1875rem;
  border: none;
  transition: all 0.2s ease-in-out;
}
.editWord {
  margin: 0 auto;
  width: 80%;
  border-radius: .5rem;
}

.heading {
  margin-top: 1.5rem;
  text-align: center;
  font-weight: 900;
  font-size: 0.375rem;
  color: rgb(16, 137, 211);
}
</style>